package com.osce.ex.controller;

import com.csce.domain.entity.exam.ExExam;
import com.osce.common.annotation.Log;
import com.osce.common.core.controller.BaseController;
import com.osce.common.core.entity.AjaxResult;
import com.osce.common.core.page.TableDataInfo;
import com.osce.common.enums.BusinessType;
import com.osce.common.utils.poi.ExcelUtil;
import com.osce.interfaces.ex.IExExamService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 考试管理Controller
 *
 * @author zzx
 * @since 2023-08-09
 */
@RestController
@RequestMapping("/ex/exam")
public class ExExamController extends BaseController {

    @Resource
    private IExExamService exExamService;

    /**
     * 查询考试管理列表
     */
    @PreAuthorize("@ss.hasPermi('ex:exam:list')")
    @GetMapping("/list")
    public TableDataInfo list(ExExam exExam) {
        startPage();
        List<ExExam> list = exExamService.selectExExamList(exExam);
        return getDataTable(list);
    }

    /**
     * 导出考试管理列表
     */
    @PreAuthorize("@ss.hasPermi('ex:exam:export')")
    @Log(title = "考试管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ExExam exExam) {
        List<ExExam> list = exExamService.selectExExamList(exExam);
        ExcelUtil<ExExam> util = new ExcelUtil<ExExam>(ExExam.class);
        util.exportExcel(response, list, "考试管理数据");
    }

    /**
     * 获取考试管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('ex:exam:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(exExamService.selectExExamById(id));
    }

    /**
     * 新增考试管理
     */
    @PreAuthorize("@ss.hasPermi('ex:exam:add')")
    @Log(title = "考试管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ExExam exExam) {
        return toAjax(exExamService.insertExExam(exExam, null));
    }

    /**
     * 创建考试
     */
    @PreAuthorize("@ss.hasPermi('ex:exam:add')")
    @Log(title = "创建考试", businessType = BusinessType.INSERT)
    @PostMapping("/create")
    public AjaxResult create(@Validated @RequestBody ExExam exExam) {
        return toAjax(exExamService.create(exExam));
    }

    /**
     * 修改考试管理
     */
    @PreAuthorize("@ss.hasPermi('ex:exam:edit')")
    @Log(title = "考试管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ExExam exExam) {
        return toAjax(exExamService.updateExExam(exExam));
    }

    /**
     * 删除考试管理
     */
    @PreAuthorize("@ss.hasPermi('ex:exam:remove')")
    @Log(title = "考试管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(exExamService.deleteExExamByIds(ids));
    }
}
